﻿using System;
using ZFine.Application.Gas;
using ZFine.Application.SystemManage;
using ZFine.Code;
using ZFine.Domain.Entity.Gas;
using ZFine.Domain.Entity.SystemManage;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace ZFine.Web.Areas.Gas.Controllers
{
    public class DiningRecordController : ControllerBase
    {
        private DiningRecordApp diningRecordApp = new DiningRecordApp();
        private ResidentApp residentApp = new ResidentApp();

        [HttpGet]
        [HandlerAuthorize(ignore:false)]
        public override ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize(ignore: false)]
        public override ActionResult Form()
        {
            return View();
        }
        [HandlerAuthorize(ignore: false)]
        public override ActionResult Details()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, DiningRecordEntity in_diningRecord, string StartDate, String EndDate)
        {
            List<DiningRecordEntity> l_diningRecord = diningRecordApp.GetList(pagination, in_diningRecord.DiningSpan, in_diningRecord.IDNumber, in_diningRecord.RName,StartDate,EndDate);
            //因为有部分车牌没有记录，需要使用左连接
            var rows = l_diningRecord;
            var data = new
            {
                page = pagination.page,//当前页  1  2 3 之类
                records = pagination.records,//总条数  这里应该是18
                rows = rows,//分页的数据
                total = pagination.total,//页数
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = diningRecordApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(DiningRecordEntity diningRecord, string permissionIds, string keyValue)
        {
            //只修改，不新增
            diningRecordApp.SubmitForm(diningRecord, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize(ignore:false)]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            return Success("删除成功。");
        }
    }
}
